<template>
    <a-modal
        :title="title"
        :width="600"
        :visible="visible"
        :confirmLoading="confirmLoading"
        @ok="handleOk"
        @cancel="handleCancel"
        cancelText="关闭">
        
        <a-spin :spinning="confirmLoading">
            <a-form-model ref="form" :model="model" :rules="validatorRules">
                 <a-form-model-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    prop="dictName"
                    required
                    label="字典名称">
                      <a-input placeholder="请输入字典名称" v-model="model.dictName"/>
                 </a-form-model-item>

                 <a-form-model-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    prop="dictCode"
                    required
                    label="字典编码">
                         <a-input placeholder="请输入字典编码" v-model="model.dictCode"/>
                 </a-form-model-item>

                  <a-form-model-item
                    :labelCol="labelCol"
                    :wrapperCol="wrapperCol"
                    label="描述">
                    <a-input v-model="model.description"/>
                  </a-form-model-item>
            </a-form-model>
        </a-spin>
    </a-modal>
</template>
<script>
export default {
    name: 'DictForm',
    data() {
        return {
            title: '操作',
            visible: false,
            confirmLoading: false,
            model: {},
            labelCol: {
                xs: { span: 24 },
                sm: { span: 5 }
            },
            wrapperCol: {
                xs: { span: 24 },
                sm: { span: 16 }
            },
            validatorRules: {
                dictName: [{ required: true, message: '请输入字典名称!' }],
                dictCode: [
                    { required: true, message: '请输入字典编码!' },
                    { validator: this.validateDictCode }]
          }
        }
    },
    methods: {
       add() {
        this.edit({})
      },
      edit(record) {
        if (record.id) {
          this.visiblekey = true
        } else {
          this.visiblekey = false
        }
        this.model = Object.assign({}, record)
        this.visible = true
      },
      handleCancel() {
          this.visible = false;
      },
      handleOk() {
          this.visible = false;
      },
      close() {
        this.$emit('close')
        this.visible = false
        this.$refs.form.resetFields();
      }
    }
}
</script>